package com.yue92.datalife.repository;

import com.yue92.datalife.model.RecordItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.time.LocalDate;
import java.util.List;

public interface RecordItemRepository extends JpaRepository<RecordItem, Long> {

    List<RecordItem> getAllByRecordIdAndRecordDate(Long recordId, LocalDate recordDate);

    @Query(value = "select sum(value) from record_item where record_id = ?1 and record_date = ?2", nativeQuery = true)
    Integer sum(Long recordId, LocalDate recordDate);

    Boolean existsByRecordId(Long recordId);
}
